/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.magostini.mailservice;

import it.magostini.mailservice.sender.AcceptFulFillSender;
import it.magostini.mailservice.sender.CommentSender;
import it.magostini.mailservice.sender.ConfirmFulFillSender;
import it.magostini.mailservice.sender.FulFillSender;
import it.magostini.mailservice.sender.InviteSender;
import it.magostini.mailservice.sender.PreRegistationSender;
import it.magostini.mailservice.sender.ReFulFillSender;
import it.magostini.mailservice.sender.RetrievePasswordSender;
import it.magostini.mailservice.dto.WaveWishFullFil;
import it.magostini.mailservice.sender.FulFillWaveWishSender;
import java.util.Collection;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Repository;

/**
 *
 * @author marco
 */
@Repository(value = "mailService")
public class MailService {
    Logger log =Logger.getLogger("INTEGRATION-MAILSERVICE");

            private JavaMailSender mailSender;

            private VelocityEngine velocityEngine;

            @Autowired
            public void setMailSender(JavaMailSender mailSender) {
                log.info("SET MAIL SENDER");
                this.mailSender = mailSender;
            }

            @Autowired
            public void setVelocityEngine(VelocityEngine velocityEngine) {
                this.velocityEngine = velocityEngine;
            }

    @Async
    public void sendPreRegistrationEmail(String username,
            String password,
             String email,
            String url) {

        
        
                log.info("sending mail to "+email);
                    PreRegistationSender sender = new PreRegistationSender(mailSender,email,username,password,velocityEngine,url);
                    sender.run();
                
                

    }

    @Async
    public void sendRetievePasswordEmail(String username, String password, String email,String lg) {
                log.info("sending RetievePasswordEmail to "+email);
                    RetrievePasswordSender sender = new RetrievePasswordSender(mailSender,email,username,password,lg,velocityEngine);
                    sender.run();

                
    }

    
    @Async
    public void sendCommentEmail(String email,String userName,String idWish, String titleWish, String textWish, String userNameComment,
                                 String comment, String url) {
      log.info("sending CommentEmail to "+email);
                        CommentSender sender = new CommentSender(mailSender,
                                                             email,
                                                             userName,
                                                             userNameComment,
                                                             idWish,
                                                             titleWish,
                                                             textWish,
                                                             comment,
                                                             velocityEngine,
                                                             url);
                    sender.run();
    }
     @Async
    public void sendFulFillEmail(String usernameWishOwner,
                                 String emailWishOwner,
                                 String urlImage,
                                 String text,
                                 String link,
                                 String usernameFulFill,
                                 String emailFulFill,
                                 Long idWish) {
         log.info("sending FulFillEmail to "+emailWishOwner+" for "+emailFulFill);
         FulFillSender sender = new FulFillSender(mailSender,
                                                  usernameWishOwner,
                                                  emailWishOwner,
                                                  urlImage,
                                                  text,
                                                  link,
                                                  usernameFulFill,
                                                  emailFulFill,
                                                  idWish,
                                                  velocityEngine);
         sender.run();

    }

    @Async
    public void sendAcceptFulFill(String ffText, String ffLink,
                                    String ffUrlImage,
                                    String ffCreatorUsername, String ffCreatoremail,
                                    String userAuthUsername, String userAuthEmail,
                                    String idWish,
                                    String wishTitle,
                                    String wishText, String wishUrlImage,
                                    String wishLink) {


        log.info("sending AcceptFulFillEmail ");
         AcceptFulFillSender sender = new AcceptFulFillSender(mailSender,
                                                  ffText,ffLink,ffUrlImage,ffCreatorUsername,ffCreatoremail,userAuthUsername,userAuthEmail,
                                                 idWish, wishTitle,wishText,wishUrlImage,wishLink,
                                                  velocityEngine);
         sender.run();
    }

    public void sendReFulFill(String ffText, String ffLink,
                                    String ffUrlImage,
                                    String ffCreatorUsername, String ffCreatoremail,
                                    String userAuthUsername, String userAuthEmail,
                                     String idWish,
                                     String wishTitle,
                                    String wishText, String wishUrlImage,String wishLink
            ){
             log.info("sending ReFulFillEmail ");
         ReFulFillSender sender = new ReFulFillSender(mailSender,
                                                  ffText,
                                                  ffLink,
                                                  ffUrlImage,
                                                  ffCreatorUsername,
                                                  ffCreatoremail,
                                                  userAuthUsername
                                                  ,userAuthEmail,
                                                  idWish,
                                                  wishTitle,
                                                  wishText,
                                                  wishUrlImage,
                                                  wishLink,
                                                  velocityEngine);
         sender.run();
        
    }


    @Async
    public void sendConfirmFulFill(String ffText, String ffLink,
                                    String ffUrlImage,
                                    String ffCreatorUsername, String ffCreatoremail,
                                    String userAuthUsername, String userAuthEmail,
                                    String idWish,
                                    String wishTitle,
                                    String wishText,
                                    String wishUrlImage,
                                    String wishLink) {


        log.debug("sending AcceptFulFillEmail ");
         ConfirmFulFillSender sender = new ConfirmFulFillSender(mailSender,
                                                  ffText,ffLink,ffUrlImage,ffCreatorUsername,ffCreatoremail,userAuthUsername,userAuthEmail,
                                                 idWish, wishTitle,wishText,wishUrlImage,wishLink,
                                                  velocityEngine);
         sender.run();
    }


    @Async
    public void invite(String username, String urlImageUser, List<String> emails) {
        log.info("sending inviteEmail ");
         InviteSender sender = new InviteSender(mailSender,
                                                       username, urlImageUser,emails,
                                                  velocityEngine);
         sender.run();
    }
    //BY SCHEDULER
//    @Async
    public void sendFulFillWaveWishEmail(String  email,String username, String idWish,
                                            String titleWish,String textWish,String linkWish,String wishUrlImage,
                                            Collection<WaveWishFullFil> listFullFilPremium, Collection<WaveWishFullFil> listFullFilWeb) {

        FulFillWaveWishSender sender = new FulFillWaveWishSender(mailSender,
                                            email, username, idWish, titleWish, textWish, linkWish, wishUrlImage,
                                            listFullFilPremium, listFullFilWeb, velocityEngine);
        sender.run();

    }

   
}
